<?php

/**
 * SmartPHP framework
 *
 * @name SmartPHP framework
 * @package SmartPHP
 * @author 费尔 <admin@xuai.cn>
 * @version 3.0
 * @link http://www.SmartPHP.cn
 * @copyright SmartPHP.cn
 * @license <a href="http://www.SmartPHP.cn">SmartPHP</a>
 */

namespace Base;

/**
 * 压缩处理类
 *
 * @author 费尔 <admin@xuai.cn>
 */
class Compress {

    /**
     * 压缩css
     * @access public
     * @param string $content
     * @return string
     */
    public static function css(&$content) {
        $content = str_replace(["\r\n", "\r", "\n", "\t", "  ", "    ", "    "], '', preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $content));
        return $content;
    }

    /**
     * 压缩HTML
     * @access public
     * @param string $content
     * @return string
     */
    public static function html(&$content) {
        $content = preg_replace(['/\?><\?php/', '~>\s+<~', '~>(\s+\n|\r)~', "/> *([^ ]*) *</", "/[\s]+/", "/<!--[^!]*-->/", "/ \"/", "'/\*[^*]*\*/'"], ['', '><', '>', ">\\1<", ' ', '', "\"", ''], $content);
        return $content;
    }

}
